package com.taobaolite.user;

import org.springframework.web.bind.annotation.RequestBody;

public class UserBody {

    // TODO: 增加参数检查
    private Long userId;
    private Double balance;
    private UserType type;
    private String email;
    private String username;
    private String password;

    private String name; // nullable
    private String description; // nullable
    private String logoPath; // nullable

    public UserBody() {}

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Double getBalance() {
        return balance;
    }

    public void setBalance(Double balance) {
        this.balance = balance;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType type) {
        this.type = type;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLogoPath() {
        return logoPath;
    }

    public void setLogoPath(String logoPath) {
        this.logoPath = logoPath;
    }

    public boolean isLegalRequest() {
        if (password != null && password.length() > 0 &&
            balance != null &&
            type != null &&
            email != null && email.length() > 0) {
            switch (type) {
                case ADMIN: return true;
                case STORE: return username != null && username.length() > 0 &&
                        description != null && description.length() > 0 &&
                        logoPath != null && logoPath.length() > 0;
                case GUEST: return username != null && username.length() > 0;
            }
        }
        return false;
    }
    public RespBody toRespBody(String tokenName, String tokenValue){
        return new RespBody(this.getUserId(),
                this.getBalance(),
                this.getType(),
                this.getEmail(),
                this.getUsername(),
                this.getPassword(),
                this.getName(),
                this.getDescription(),
                this.getLogoPath(),
                tokenName,
                tokenValue);
    }
}

// TODO: 尝试使用Apifox生成代码
